package 力扣._8038_收集元素的最少操作次数;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Solution {
    public int minOperations(List<Integer> nums, int k) {
        Set<Integer> set = new HashSet<>();
        for (int i = nums.size()-1; i >=0 ; i--) {
            if(nums.get(i)<=k)
                set.add(nums.get(i));

            if(set.size()==k)
                return nums.size()-i;
        }
        return nums.size();
    }
}
